package GUI;

import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;


import Controler.Return_Book_controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.LineBorder;
/**
  * @author Lucie
 * Class name  Lend_book_panel
 * extend  Abstract_Jpanel
 * purpose: this panel get copy number from the user and call the controller 
 * to return this copy
 */
public class Return_Book_panel extends Abstract_Jpanel {
	private JTextField textFieldcopy;

	/**
	 * Create the panel.
	 */
	public Return_Book_panel() {
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(35, 49, 572, 249);
		add(panel);
		panel.setLayout(null);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(SystemColor.control, 6));
		panel_1.setBackground(new Color(220, 220, 220));
		panel_1.setBounds(63, 44, 427, 143);
		panel.add(panel_1);
		panel_1.setLayout(null);
		
		textFieldcopy = new JTextField();
		textFieldcopy.setBounds(145, 22, 167, 20);
		panel_1.add(textFieldcopy);
		textFieldcopy.setColumns(10);
		
		JLabel lblCopyNumber = new JLabel("copy number:");
		lblCopyNumber.setBounds(28, 15, 93, 31);
		panel_1.add(lblCopyNumber);
		lblCopyNumber.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblEnterThCopy = new JLabel("enter the copy number you like to return");
		lblEnterThCopy.setBounds(38, 57, 304, 20);
		panel_1.add(lblEnterThCopy);
		lblEnterThCopy.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblEnterThCopy.setForeground(Color.RED);
		
		JLabel lblReturnAnItem = new JLabel("Return an Item");
		lblReturnAnItem.setForeground(new Color(25, 25, 112));
		lblReturnAnItem.setFont(new Font("MV Boli", Font.BOLD, 27));
		lblReturnAnItem.setBounds(67, 11, 247, 37);
		add(lblReturnAnItem);
		/*
		  *btnDelete=When you click this button you will call get_data(get_copy_id())
		 * a method of the controller of this panel if this method return true we will
		 * call the methods of this class next_screen_success(),empty_text_fields();
		 * else we call next_screen_faild(return_controler.get_msg());	
		 * return_controler.get_msg(); return the msg from the controller with all
		 * the error msg.
		 */
		JButton btnReturn = new JButton("return");
		btnReturn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Return_Book_controler return_controler=new Return_Book_controler();
				if(return_controler.get_data(get_copy_id()))
				{
					next_screen_success();
					empty_text_fields();
					
				}
				else {
					next_screen_faild(return_controler.get_msg());
					
				}
				
				
				
			}
		});
		btnReturn.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnReturn.setBounds(484, 309, 104, 37);
		add(btnReturn);

	}

	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	public String get_copy_id()
	{
		return textFieldcopy.getText();
	}
	/**
	 * this method display showMessageDialog with a success msg
	 */
	public void next_screen_success()
	{
		JOptionPane.showMessageDialog(this,"apply success");
	}
	/**
	 * this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"apply faild "+msg);
	}
	/**
	 * this method empty textFieldcopy
	 */
	public void empty_text_fields()
	{
		textFieldcopy.setText(null);
		
		
	
	}
	
}
